/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2024-12-03
 * Time:23:46
 */
public class Test {
        public int removeDuplicates(int[] nums) {
            int count=1;//不重复元素
            for(int i=1;i < nums.length;i++){
                if(nums[count-1]!=nums[i]){//count-1是重复元素的最后一个元素
                    nums[count++]=nums[i];
                }
            }
            return count;
        }
        //盛水最多的容器
        public int maxArea(int[] height) {
            int left=0;
            int right=height.length-1;
            int max=0;
            while(left<right){
                int v=Math.min(height[left],height[right])*(right-left);
                max=Math.max(max,v);
                if(height[left]<height[right]){
                    left++;
                }else{
                    right--;
                }
            }
            return max;
        }
//快乐数
        //求平方和
        public int bitSum(int n){
            int sum=0;
            while(n!=0){
                int m=n%10;
                sum+=m*m;
                n/=10;
            }
            return sum;
        }
        public boolean isHappy(int n) {
            int slow=n;//第一个数
            int fast=bitSum(n);//为第二个数
            while(slow!=fast){
                slow=bitSum(slow);//每次走一步
                fast=bitSum(bitSum(fast));//每次走两步
            }
            return slow==1;
        }
        //移动0
        public void moveZeroes(int[] nums) {
            for (int cur = 0, dest = -1; cur < nums.length; cur++) {
                if (nums[cur] != 0) {
                    dest++;
                    int tmp = nums[cur];
                    nums[cur] = nums[dest];
                    nums[dest] = tmp;
                }
            }
        }

    }
